package org.example.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.example.domain.entity.Category;
import org.example.domain.entity.ProductId;
import org.example.domain.entity.ProductSku;
import org.example.domain.model.PageData;
import org.example.domain.model.Result;
import org.example.service.IFmFrontedGoodsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home")
public class FmFrontedGoodsController {
    private IFmFrontedGoodsService goodsService;
    private Log log= LogFactory.getLog(FmFrontedGoodsController.class);
    public FmFrontedGoodsController(IFmFrontedGoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @PostMapping("/goods")
    public Result queryGoods(){
        Map<String, Object> map = goodsService.queryShufflingImg();
        return Result.buildSuccess(map);
    }
    @PostMapping("/twogoods")
    public Result queryTwoGoods(@RequestBody String categoryid){
        List<Category> categories = goodsService.queryTwoGoods(categoryid);

        return Result.buildSuccess(categories);
    }
    @GetMapping("/pro")
    public Result queryProducts(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){
        PageData<ProductId> pageData = goodsService.queryProduct(page, limit);

        return Result.buildSuccess(pageData);
    }
    @PostMapping("pic_pro")
    public Result queryPickPro(@RequestBody Map<String,String> product){
        PageData<ProductId> productIdPageData = goodsService.queryPickPro(Integer.parseInt(product.get("page")),Integer.parseInt(product.get("categoryId")), Integer.parseInt(product.get("pagesize")));
        return Result.buildSuccess(productIdPageData);
    }



}
